
#include <iostream>
#include <string>
#include <functional>
#include "serve.h"
#include "Log.h"
#include "Telecontrol.h"
#include "Intaddr.h"

// 调用方式: ./serve port
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        std::cerr << "使用方式错误,正确调用方式 ./serve port" << std::endl;
        exit(Err_Use);
    }
    zmh::Intaddr serve_addr(AF_INET, std::stoi(argv[1]));

    zmh::Telecontrol telcont;

    // 是否传参数取决于是否需要服务类内部进行传参
    auto handler = [&telcont](std::string mesage, int fd, const zmh::Intaddr &peer)
    {
        std::string ret = telcont.Excute(mesage);
        write(fd, ret.c_str(), ret.size());
    };

    zmh::serve ser(serve_addr, handler);
    ser.start();
    return 0;
}
